import moment from "moment";

export const isValidPhoneNumber = (mobile: string): boolean => {
  const phoneRegex = /^1[3-9]\d{9}$/;
  return phoneRegex.test(mobile);
};

// 秒转"X分钟Y秒"格式化函数
export const formatDuration = (seconds: number | undefined | null): string => {
  if (!seconds || seconds <= 0) return '-';
  const duration = moment.duration(seconds, 'seconds');
  const min = Math.floor(duration.asMinutes());
  const sec = duration.seconds();
  if (min > 0 && sec > 0) return `${min}分钟${sec}秒`;
  if (min > 0) return `${min}分钟`;
  if (sec > 0) return `${sec}秒`;
  return '-';
};